import React, {memo, useEffect,useState} from 'react';
import {shallowEqual, useDispatch, useSelector} from 'react-redux'

import { Table, Tag, Space, Divider, Button, Modal, message,Spin } from 'antd';
import { rentalProcessQuery } from '../../services';
import { TimeProcess } from '../../utils';

export default memo(function RentalProcessQuery(){
    const user = useSelector(state => state.getIn(["user"]))
    const student_number = {student_number: user.user_id};
    

    const [rentalInfo, setRentalInfo] = useState([])
    const [dataLength, setDataLength] = useState(0)

    // console.log(user);
    // console.log("租赁结果查询");
    //用学号去查审核记录
    
    useEffect(()=> {
        rentalProcessQuery(student_number).then(res => {
            // console.log(res);
            setRentalInfo(res.data)
            setDataLength(res.dataLength)
            // message.success(`查询成功,共查询到${res.dataLength}条租赁申请记录!`)
        })

    }, [rentalInfo])

    const columns = [
        {
          title: '寝室号',
          dataIndex: 'room_number',
          key: 'room_number',
        },
        {
          title: '租赁起始时间',
          dataIndex: 'rental_beginning_date',
          key: 'rental_beginning_date',
          render: time => {
            let realTime = TimeProcess(time);
            return (
              <div>{realTime}</div>
            )
          }
        },
        {
          title: "租赁办理人",
          dataIndex: "house_cheif",
          key: "house_cheif",
          
        },
        {
          title: '已缴租赁费用',
          dataIndex:'rental_payment',
          key: 'rental_payment',
        
        },
        {
          title: '审核状态',
          dataIndex: 'rental_is_examin',
          key: 'rental_is_examin',
          render: item => {
            var displayText = "未审核"
            var color = 'red'
            // console.log(text);
            if(item == 1)
            {
                displayText = "已审核"
                color = 'green'
            }
            return (
              <>
                <Tag color={color}  key={displayText}>{displayText}</Tag>
              </>
            )

          }
        },
        {
            title: '审核日期',
            dataIndex:'rental_examin_date',
            key: 'rental_examin_date',
            render: time => {
                let realTime = TimeProcess(time);
                return (
                  <div>{realTime}</div>
                )
              }
          
          },
          {
            title: '审核人',
            dataIndex:'rental_examin_admin',
            key: 'rental_examin_admin',
          
          },
          {
            title: '审核人联系方式',
            dataIndex:'rental_examin_admin_number',
            key: 'rental_examin_admin_number',
          
          },
      ];

    return (
        <div>
            <Divider orientation='left'>租赁申请结果查询</Divider>
            <div style={{margin:'20px'}}>共查询到{dataLength}条租赁申请记录!若有疑问,请及时联系管理员确认!</div>
            <div>
                <Table columns={columns} dataSource={rentalInfo} style={{minHeigh:"100%"}}/>
            </div>
        </div>
    )
})